package cn.wp.ewallet.wallet.web.controller;

import cn.wp.common.core.Wp;
import cn.wp.common.core.dto.WpResult;
import cn.wp.common.core.model.WpPage;
import cn.wp.common.core.web.annotation.ClearInterceptor;
import cn.wp.common.core.web.interceptor.LoginInterceptor;
import cn.wp.ewallet.wallet.extension.constant.EwalletWalletConstant;
import cn.wp.ewallet.wallet.model.dto.ExchangeMoneyDto;
import cn.wp.ewallet.wallet.model.dto.ExchangeMoneyInfoDto;
import cn.wp.ewallet.wallet.model.dto.ExchangeMoneyReqDto;
import cn.wp.ewallet.wallet.model.dto.UsdtExchangeShqcDto;
import cn.wp.ewallet.wallet.service.ExchangeMoneyInfoService;
import cn.wp.ewallet.wallet.service.MoneyChangeService;
import cn.wp.ewallet.wallet.service.WalletInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 兑换申请单-控制层
 * Created by zhangyongli on 2020/01/09
 */
@RestController
@RequestMapping(Wp.WebContext + "/ewallet/wallet/exchangeMoney")
@Api(tags = "兑换申请单")
public class ExchangeMoneyInfoController {

    @Autowired
    private ExchangeMoneyInfoService exchangeMoneyInfoService;

    @Autowired
    private MoneyChangeService moneyChangeService;

    @Autowired
    private WalletInfoService walletInfoService;

    @PostMapping("/addExchangeMoneyInfo")
    @ApiOperation("兑换申请提交")
    public WpResult addExchangeMoneyInfo(ExchangeMoneyReqDto exchangeMoneyReqDto) {
        //校验交易密码
        if (!walletInfoService.checkTransPwd(exchangeMoneyReqDto.getTransPwd())) {
           return new WpResult().failure(EwalletWalletConstant.CHECK_TRANSPWD_FAILED_CODE, "交易密码校验失败");
        }
        return moneyChangeService.exchangeMoneyApply(exchangeMoneyReqDto);
    }

    /**
     * 处理兑换申请单的信息
     * @return
     */
    @PostMapping("/handleExchangeMoneyOrder")
    @ApiOperation("处理兑换申请单")
    public WpResult handleExchangeMoneyOrder(ExchangeMoneyDto exchangeMoneyDto){
        return moneyChangeService.exchangeMoneyHandler(exchangeMoneyDto);
    }


    /**
     * 处理兑换申请单的信息
     * @return
     */
    @PostMapping("/calculateUsdtToShqc")
    @ApiOperation("计算USDT兑换SHQC数量")
    public WpResult calculateUsdtToShqc(UsdtExchangeShqcDto usdtExchangeShqcDto){
        return new WpResult().success(exchangeMoneyInfoService.calculateUsdtToShqc(usdtExchangeShqcDto));
    }
}